/******************************************************
 * @file utf-16be.c
 * @author Destiny 
 * @brief utf-16be解码程序
 * 
 * @version 0.1
 * @date 2024-07-18
 *****************************************************/
#include <config.h>
#include <encoding_manager.h>
#include <string.h>

static int isUtf16beCoding(uint8_t *pucBufHead);
static int Utf16beGetCodeFrmBuf(uint8_t *pucBufStart, uint8_t *pucBufEnd, uint32_t *pdwCode);

static T_EncodingOpr g_tUtf16beEncodingOpr = {
	.name          = "utf-16be",
	.iHeadLen	   = 2,
	.isSupport     = isUtf16beCoding,
	.GetCodeFrmBuf = Utf16beGetCodeFrmBuf,
};


static int isUtf16beCoding(uint8_t *pucBufHead)
{
	const char aStrUtf16be[] = {0xFE, 0xFF, 0};
	
	if (strncmp((const char*)pucBufHead, aStrUtf16be, 2) == 0)
	{
		
		return 1;
	}
	else
	{
		return 0;
	}
}


static int Utf16beGetCodeFrmBuf(uint8_t *pucBufStart, uint8_t *pucBufEnd, uint32_t *pdwCode)
{
	if (pucBufStart + 1 < pucBufEnd)
	{
		*pdwCode = (((uint32_t)pucBufStart[0])<<8) + pucBufStart[1];
		return 2;
	}
	else
	{
		
		return 0;
	}
}


int  Utf16beEncodingInit(void)
{
	AddFontOprForEncoding(&g_tUtf16beEncodingOpr, GetFontOpr("freetype"));
	AddFontOprForEncoding(&g_tUtf16beEncodingOpr, GetFontOpr("ascii"));
	return RegisterEncodingOpr(&g_tUtf16beEncodingOpr);
}



